
#include "sockets.h"

extern "C" void *SOCKET_Socket(void)
{
    Sockets *pSock = NULL;

    pSock = new Sockets;
    return pSock;
}/* end of SOCKET_Socket() */

extern "C" int SOCKET_Connect(void *pSock, const char *pHost, int port)
{
	bool bConnect;

	if(pSock == NULL)
	{
		return -1;
	}

	bConnect = ((Sockets *)pSock)->Connect(pHost, port);

	if(bConnect == true)
	{
		return 0;
	}
	else
	{
		return -1;
	}
}/* end of SOCKET_Connect() */

extern "C" void SOCKET_Close(void *pSock)
{
    MBBMS_LOGD("--->%s()     [pSock=0x%x]",__func__, pSock);
    if ((pSock == NULL) || (INVALID_SOCKET == (int)pSock))
    {
        return;
    }

    ((Sockets *)pSock)->Close();

    delete ((Sockets *)pSock);
}/* end of SOCKET_Close() */

extern "C" int SOCKET_Receive(void *pSock, char *pBuf, int len, int flag)
{
	if(pSock == NULL)
	{
		return -1;
	}

	return ((Sockets *)pSock)->Receive(pBuf, len, flag);
}/* end of SOCKET_Receive() */

extern "C" int SOCKET_Send(void *pSock, const char *pBuf, int len, int flag)
{
	if(pSock == NULL)
	{
		return -1;
	}

	return ((Sockets *)pSock)->Send(pBuf, len, flag);
}/* end of SOCKET_Send() */
